package com.gtxy.yyf.doris.catrgory;



import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.gtxy.yyf.doris.Category;
import com.gtxy.yyf.doris.category.dao.CategoryMapper2;
import com.gtxy.yyf.doris.core.PageData;
import com.gtxy.yyf.doris.core.Result;
import com.gtxy.yyf.doris.vo.CategoryQueryVo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;


/**
 * 测试案例controller
 */

@Controller
@RequestMapping("")
public class CategoryController {

    private static final Logger log= LoggerFactory.getLogger(CategoryController.class);

     @Autowired
     CategoryMapper2 categoryMapper;

    /**
     * 列表查询： 原生方法
     * @return
     */
    @GetMapping("/list")
    @ResponseBody
    public Result listDomain(){
        log.info("no:"+"test");
        log.debug("debug"+"test debug");
        log.error("error"+"test debug");
        return Result.success(categoryMapper.selectList(null)) ;
    }


    /**
     * 自定义查询
     * @return
     */
    @GetMapping("/list2")
    @ResponseBody
    public Result listDomain2(){
        log.info("no:"+"list2");
        log.debug("debug"+"test debug");
        log.error("error"+"test debug");
        return Result.success(categoryMapper.findAll()) ;
    }

    /**
     * 自定义查询分页
     * @param vo
     * @return
     */
    @GetMapping("/listPage")
    @ResponseBody
    public Result listPage(CategoryQueryVo vo){
        Page<Category> page=new Page<>(vo.getPageNo(),vo.getPageSize());
        IPage iPage=categoryMapper.selectGetPageVo(page,vo);
        PageData pageData = new PageData(vo.getPageNo(), vo.getPageSize(), iPage.getTotal(), iPage.getRecords());
        return Result.success( pageData);
    }

    @ResponseBody
    @PostMapping("add")
    public Result add(@RequestBody Category order){
        categoryMapper.insert(order);
        return Result.success();
    }

    @GetMapping("/test")
    @ResponseBody
    public Result toTest(){
        return Result.success();
    }
}
